package com.javatest.springbootquartz.job;

import com.javatest.springbootquartz.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @create 2019-07-04 下午12:26
 */
@Slf4j
@DisallowConcurrentExecution
@Component
public class JobOnce implements Job {

    @Autowired
    private TestService testService;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        JobDataMap data = context.getTrigger().getJobDataMap();
        String invokeParam = (String) data.get("invokeParam");
        //在这里实现业务逻辑
        log.info(context.getJobDetail().getKey() + " do job at " + LocalDateTime.now() + " with parameter:" + invokeParam);
        testService.print();
    }
}
